package com.px.user.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import com.px.user.model.PagingModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@SuperBuilder
@NoArgsConstructor
@Entity(name = "charge_channel")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "充值通道对象", description = "充值通道字段")
@org.hibernate.annotations.Table(appliesTo = "charge_channel", comment = "充值通道表")
public class ChargeChannel extends PagingModel {

    @Id
    @ApiModelProperty(value = "主键")
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @ApiModelProperty(value = "通道名称", example = "支付宝")
    @Column(columnDefinition = "varchar(128) comment '通道名称'")
    private String name;

    // TODO 通道管理
    @ApiModelProperty(value = "通道地址", example = "http://xxx")
    @Column(columnDefinition = "varchar(512) comment '通道地址'")
    private String url;

    @ApiModelProperty(value = "可选金额列表")
    @Column(columnDefinition = "varchar(1024) comment '可选金额列表'")
    private String value;

    @ApiModelProperty(value = "最小金额")
    @Column(columnDefinition = "decimal(12,2) default 0 comment '最小金额'")
    private BigDecimal start;

    @ApiModelProperty(value = "最大金额")
    @Column(columnDefinition = "decimal(12,2) default 0 comment '最大金额'")
    private BigDecimal end;

    @Column(columnDefinition = "bit default 0 comment '已禁用: 1#禁用,0#未禁用'")
    @ApiModelProperty(value = "已禁用: 1#禁用,0#未禁用", example = "0")
    private Integer disabled;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;

    @ApiModelProperty(value = "支付渠道编号", example = "02")
    @Column(columnDefinition = "varchar(10) comment '支付渠道编号'")
    private String channelNo;

    @ApiModelProperty(value = "支付类型", example = "支付宝")
    @Column(columnDefinition = "varchar(20) comment '通道地址'")
    private String paymentType;

    @ApiModelProperty(value = "是否是固定金额", example = "true：是固定金额； false：非固定金额")
    @Column(columnDefinition = "int comment '是否是固定金额'")
    private int isfixedAmount;

    @ApiModelProperty(value = "固定金额", example = "100,500,1000,2000,5000,10000,50000,100000")
    @Column(columnDefinition = "varchar(50) comment '充值固定金额'")
    private String fixedAmount;
}
